﻿using System;

namespace VsxToolset
{
  // ==================================================================================
  /// <summary>
  /// This abstract class is intended to be a base class for uotput window pane 
  /// definitions.
  /// </summary>
  // ==================================================================================
  public abstract class OutputPaneDefinition
  {
    #region

    private readonly string _Name = "<Name not defined>";
    private readonly bool _InitiallyVisible = true;
    private readonly bool _ClearWithSolution = false;
    private readonly bool _ThreadSafe = true;
    private bool _IsSilent;

    #endregion

    #region Lifecycle methods

    // --------------------------------------------------------------------------------
    /// <summary>
    /// Creates an instance of the class by obtaining the attributes decorating the 
    /// class.
    /// </summary>
    // --------------------------------------------------------------------------------
    protected OutputPaneDefinition()
    {
      foreach (object attr in GetType().GetCustomAttributes(false))
      {
        PaneNameAttribute paneNameAttr = attr as PaneNameAttribute;
        if (paneNameAttr != null)
        {
          _Name = paneNameAttr.Value;
          continue;
        }
        InitiallyVisibleAttribute initVisAttr = attr as InitiallyVisibleAttribute;
        if (initVisAttr != null)
        {
          _InitiallyVisible = initVisAttr.Value;
          continue;
        }
        ClearWithSolutionAttribute clearWithSolAttr = attr as ClearWithSolutionAttribute;
        if (clearWithSolAttr != null)
        {
          _ClearWithSolution = clearWithSolAttr.Value;
          continue;
        }
        ThreadSafeAttribute threadSafeAttr = attr as ThreadSafeAttribute;
        if (threadSafeAttr != null)
        {
          _ThreadSafe = threadSafeAttr.Value;
          continue;
        }
      }
    }

    #endregion

    #region Public properties

    // --------------------------------------------------------------------------------
    /// <summary>
    /// Gets the GUID of the output window pane.
    /// </summary>
    // --------------------------------------------------------------------------------
    public virtual Guid GUID
    {
      get { return GetType().GUID; }
    }

    // --------------------------------------------------------------------------------
    /// <summary>
    /// Gets the default name of the output window pane.
    /// </summary>
    // --------------------------------------------------------------------------------
    public string Name
    {
      get { return _Name; }
    }

    // --------------------------------------------------------------------------------
    /// <summary>
    /// Gets the flag indicating if the output window pane is initially visible or not.
    /// </summary>
    // --------------------------------------------------------------------------------
    public bool InitiallyVisible
    {
      get { return _InitiallyVisible; }
    }

    // --------------------------------------------------------------------------------
    /// <summary>
    /// Gets the flag indicating if the output window pane is to be cleared when the
    /// current solution is closed.
    /// </summary>
    // --------------------------------------------------------------------------------
    public bool ClearWithSolution
    {
      get { return _ClearWithSolution; }
    }

    // --------------------------------------------------------------------------------
    /// <summary>
    /// Gets the flag indicating if writes to the output window pane are thread safe
    /// or not.
    /// </summary>
    // --------------------------------------------------------------------------------
    public bool ThreadSafe
    {
      get { return _ThreadSafe; }
    }

    // --------------------------------------------------------------------------------
    /// <summary>
    /// Gets or internally sets the flag indicating if this output window pane is a 
    /// silent pane or not.
    /// </summary>
    /// <remarks>
    /// Silent panes do not provide output.
    /// </remarks>
    // --------------------------------------------------------------------------------
    public bool IsSilent
    {
      get { return _IsSilent; }
      internal set { _IsSilent = value; }
    }

    #endregion
  }
}
